package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Before;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class OssConfiguraton {
    /**
     * 通过Spring管理对象 @Bean
     * @param aliOssProperties
     * @return
     */
    @Bean // 将AliOssUtil交由Spring容器管理
    @ConditionalOnMissingBean // 如果Spring容器中没有AliOssUtil实例 则创建它 避免重复创建Bean
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) {
        // 返回一个AliOssUtil对象 交给spring容器管理
        log.info("开始创建阿里云OSS工具类...");

        return new AliOssUtil(
                aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName()
                );
    }
}
